/*
 * Copyright (c) 2013 WDCY Information Technology Co. Ltd
 * www.wdcy.cc
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * WDCY Information Technology Co. Ltd ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you
 * entered into with WDCY Information Technology Co. Ltd.
 */
package com.monkey.web.platform.service;


import com.monkey.core.domain.permission.Permission;
import com.monkey.core.domain.resource.Menu;
import com.monkey.core.domain.role.Role;
import com.monkey.core.domain.role.RoleResourcePermission;
import com.monkey.core.domain.user.User;
import com.monkey.core.plugin.dto.MonkeyDto;
import com.monkey.core.service.BaseService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Set;

/**
 * @author Wu Tianqiang
 */
public interface RoleService extends BaseService<Role, Long> {

    void addRole(MonkeyDto monkeyDto);

    void modifyRole(MonkeyDto monkeyDto);

    /**
     * 授权角色给用户
     *
     * @param roleIds
     * @param user
     * @return
     */
    void grantRoleToUser(Long[] roleIds, User user);

    /**
     * 回收用户的角色
     *
     * @param roleIds
     * @param userId
     * @return
     */
    void recoveryRoleFromUser(Long[] roleIds, Long userId);

    /**
     * 通过用户查询出角色
     *
     * @param userId
     * @return
     */
    Set<String> findStringRoles(Long userId);

    /**
     * 从角色解析出权限
     *
     * @param roleString
     * @return
     */
    Set<String> resolvePermissionsInRole(String roleString);

    void grantPermissionToRole(Role role, Menu menu, Long[] permissionIds);

    void recoveryPermissionFromRole(Role role, Menu menu, Long[] permissionIds);

    List<Permission> getPermissionByRoleMenu(Role role, Menu menu);

    Page<RoleResourcePermission> getPermissionByRole(Role role, Pageable pageable);

}